home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-25 | 7.4 KB | 200 lines | [TEXT/CWIE] |
- //================================================================================
- // Greg Anderson
- // db+
- //
- // Cursor to an object record
- // 16 May 1994
- //================================================================================
- #pragma once
-
- #ifndef __DBELEMENTRECORD__
- #define __DBELEMENTRECORD__
-
- #include "DBRecord.h"
-
- class TDBProperty;
-
- //
- // An object record cursor contains elements and properties, both
- // stored in a balanced tree
- //
- // Fields:
- //
- // Flags
- // b31-b29: Used by AbstractDBRecord
- // b28: Set = object record (Clear = some other type of record)
- // b27-b0: Node number
- // Parent sibling (same as parent element for child at top of tree)
- // Left sibling
- // Right sibling
- //
- // Parent element (cached location of TreeOwner)
- // Child at top of element tree
- // Data record at top of property tree
- // Name property (cached location of pName in property tree)
- //
-
- enum
- {
- kParentElementWord = kIDOrParentElementIndex
- };
-
- //
- // Well-known property IDs
- //
- enum
- {
- //
- // The "name" property happens to have the same value
- // as 'pName' in AERegistry.h; however, I want to avoid
- // Macintosh include files here, so I'm redefining
- // the constant.
- //
- kNameProperty = 'pnam'
- };
-
- //================================================================================
- // Class TDBElement
- //================================================================================
- class TDBElement : public TDBRecord
- {
- //
- // ----- Fields --------------------------------------------------------------
- //
- protected:
-
- //
- // ----- Methods -------------------------------------------------------------
- //
-
- public:
- TDBElement(TDatabaseDocument* doc, long recordIndex) :
- TDBRecord(doc, recordIndex) {};
- virtual ~TDBElement();
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Methods of TAbstractRecord:
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- protected:
-
- virtual const TDBElement* DBElementRecord() const { return this; };
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Methods of TDBRecord:
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- public:
-
- virtual AConst<TDBRecord> TreeOwner(TTransaction* t) const { return this->ParentElement(t); }
- virtual void InitializeNewRecord(TTransaction* t);
- virtual void PropertyValueChanged(TTransaction* t, AConst<TDBProperty> propertyThatChanged);
- virtual CompareEnumeration CompareSortKeys(TTransaction* t, AConst<TDBRecord> secondObject) const;
- virtual Boolean RecordCanHaveElements(TTransaction* t) const;
- virtual Boolean RecordCanHaveProperties(TTransaction* t) const;
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Public interface: const methods
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- public:
-
- long NodeNumber(TTransaction* t) const { return this->RecordFlags(t) & kObjectRecordReservedRecordBits; };
-
- //
- // Methods to look up properties and elements:
- //
- AConst<TDBProperty> GetPropertyRecord(TTransaction* t, long propertyID) const;
- AConst<TDBElement> GetNamedElement(TTransaction* t, const TAbstractDataReference& nameSpec) const;
-
- //
- // Methods to get values directly from a property of this object
- //
- long GetLongwordProperty(TTransaction* t, long propertyID) const;
- // void GetStringProperty(TTransaction* t, long propertyID, CString& str, short maxLength) const;
- Boolean GetBooleanProperty(TTransaction* t, long propertyID) const { return this->GetLongwordProperty(t, propertyID); };
- void GetTypedProperty(TTransaction* t, long propertyID, TUpdataDataReference& data) const;
- // void NameString(TTransaction* t, CString& objectsName, short maxLength) const;
-
- AConst<TDBElement> ParentElement(TTransaction* t) const { return this->GetDBElementCursor(this->ParentElementIndex(t)); };
- AConst<TDBProperty> NameProperty(TTransaction* t) const { return this->GetDBPropertyCursor(this->NamePropertyIndex(t)); };
-
- //
- // Methods that return the top record of the element / property tree
- // (usually you should just use the routines above, though)
- //
- AConst<TDBElement> Elements(TTransaction* t) const { return this->GetDBElementCursor(this->TopChildIndex(t)); };
- AConst<TDBProperty> Properties(TTransaction* t) const { return this->GetDBPropertyCursor(this->TopPropertyIndex(t)); };
-
- //
- // Debugging:
- //
- virtual void Verify(TTransaction* t, Boolean verifyDeep = false) const;
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Public interface: non-const methods
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- public:
-
- //
- // Add an element or property to this element
- //
- void AddElement(TTransaction* t, AnUpdate<TDBElement> newElement);
- void AddProperty(TTransaction* t, AnUpdate<TDBProperty> newProperty);
-
- //
- // Directly change the value of a property of this element
- //
- void AddLongwordProperty(TTransaction* t, long propertyID, long newValue);
- // void AddStringProperty(TTransaction* t, long propertyID, CString& name);
- void AddBooleanProperty(TTransaction* t, long propertyID, Boolean newValue) { this->AddLongwordProperty(t, propertyID, newValue); };
- void AddTypedProperty(TTransaction* t, long propertyID, const TAbstractDataReference& data);
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Protected interface: const methods
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- protected:
-
- long ParentElementIndex(TTransaction* t) const { return this->GetRecordData(t, kParentElementWord); };
- long NamePropertyIndex(TTransaction* t) const { return this->GetRecordData(t, kNamePropertyWord); };
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Protected interface: non-const methods
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- protected:
-
- AConst<TDBProperty> GetPropertyRecordForceCreate(TTransaction* t, long propertyID);
-
- void SetNodeNumber(TTransaction* t, long newValue) { this->SetRecordFlags(t, (newValue & kObjectRecordReservedRecordBits) | (this->RecordFlags(t) & ~kObjectRecordReservedRecordBits)); };
- void SetParentElementIndex(TTransaction* t, long newValue) { this->ChangeRecordData(t, kParentElementWord, newValue); };
- void SetNamePropertyIndex(TTransaction* t, long newValue) { this->ChangeRecordData(t, kNamePropertyWord, newValue); };
-
- void SetParentElement(TTransaction* t, AConst<TDBElement> parentElement) { this->SetParentElementIndex(t, parentElement->RecordIndex()); }
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Private methods:
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- private:
-
- };
-
- //================================================================================
- // Class TObjectRecordComparisonObject
- //================================================================================
- class TObjectRecordComparisonObject : public TAbstractDBComparisonObject
- {
- private:
- const TAbstractDataReference& fSearchKey;
-
- public:
- TObjectRecordComparisonObject(const TAbstractDataReference& searchKey) : fSearchKey(searchKey) {};
-
- virtual CompareEnumeration TestObject(TTransaction* t, AConst<TDBRecord>);
- };
-
- #endif
-